<template>
  <a-modal
    title="查询条件"
    :visible="seniorSearchInfo.visible"
    @ok="handleOk"
    @cancel="handleCancel"
    :width="800"
    :maskClosable='false'
    :footer="null"
  >
    <div>
      <div v-for="(item, index) in seniorSearchInfo.sourceData" :key="index">
        <SeniorForm :componentsObject="{
            title: item.title,         
            keys: item.keys,          
            placeholder: item.placeholder,  
            type: item.type,          
            value: item.value,     
            searchType: item.searchType,
          }" 
          :key="Math.random()"
          @seniorValueReturn="seniorValueReturn"
        >
        </SeniorForm>
      </div>
      <a-row type="flex" style="border-top: 1px solid #eee; margin-top: 10px;  padding-top: 15px;">
        <a-col flex="auto" style="text-align: right; padding-right:10px;">
          <a-button type="default" @click="seniorModalReset">
            <a-icon type="delete" />
            重置
          </a-button>
        </a-col>
        <a-col flex="auto" style="text-align: left; padding-left:10px;">
          <a-button type="primary" @click="seniorModalSearch">
            <a-icon type="search" />
            查询
          </a-button>
        </a-col>
      </a-row>
    </div>
  </a-modal>
</template>

<script>


import SeniorForm from './SeniorForm'

export default {
  name: 'seniorModal',
  components: {
    SeniorForm
  },
  props: {
    seniorSearchInfo: Object,
    // seniorSearchInfo:{
    //   visible: false,  // 当前 modal 是否显示 
    //   sourceData: '',  // 源数据
    // }
  },
  data () {
    return {
      searchParam:{},
    }
  },

  mounted(){
    // console.log("当前原始数据的测试~this.seniorSearchInfo.sourceData~", this.seniorSearchInfo);

    console.log("--刚进来--cacaca--", this.searchParam);
  },

  methods: {

    // 关闭当前的 modal
    handleCancel(){
      this.seniorSearchInfo.visible = false
    },

    seniorModalReset(){
      this.searchParam = {}
      this.seniorSearchInfo.sourceData.map((item, index)=>{
        if(this.seniorSearchInfo.sourceData[index].value ==='' ){
          this.seniorSearchInfo.sourceData[index].value = null
        }else{
          this.seniorSearchInfo.sourceData[index].value = ''
        }
      })
    },

    seniorModalSearch(){
      let param = this.searchParam
      console.log("---cacaca---click---", param);
      this.$emit("seniorModalSearch", param);
    },

    // 获取form组件的值
    seniorValueReturn(e){
      console.log("测试下当前获取到的值的问题<--e-->", e);
      console.log("测试下当前获取到的值的问题<--e.currentVal-->", e.currentVal);
      // 参数值进行记录
      this.searchParam[e.keys] = e.currentVal
    }
  },

  watch: {
    
  }
}
</script>

<style lang="less" scoped>

</style>
